//
//  HLENoInernetView.m
//  HLEEmptyView
//
//  Created by hle1 on 2020/9/12.
//

#import "HLENoInternetView.h"
#import <Masonry/Masonry.h>
#import <YsToolsManager/YsToolsManager.h>
#import <YYCategories/YYCategories.h>
#import <ReactiveObjC/ReactiveObjC.h>

@implementation HLENoInternetView

+ (instancetype)noInternetViewWithImage:(UIImage *)image
                               titleStr:(NSString *)titleStr
                          reloadDataStr:(NSString *)reloadDataStr
                            reloadClick:(void (^)(void))reloadClick
{
    HLENoInternetView *noInternetView = [[self alloc] init];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [noInternetView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.centerX.mas_equalTo(0);
    }];
    
    UILabel *titleLabel = [UILabel creatLabel:titleStr textColor:[UIColor colorWithHexString:@"#9D9D9D"] fontSize:[UIFont systemFontOfSize:13] numberofLines:0];
    [noInternetView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageView.mas_bottom).offset(19);
        make.left.mas_greaterThanOrEqualTo(30);
        make.right.mas_lessThanOrEqualTo(-30);
        make.centerX.mas_equalTo(0);
    }];
    
    UIButton *btn = [UIButton buttonWithTitle:reloadDataStr fontSize:16 titleColor:[UIColor colorWithHexString:@"#333333"]];
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (reloadClick) {
            reloadClick();
        }
    }];
    
    btn.layer.cornerRadius = 4;
    btn.layer.masksToBounds = YES;
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = [UIColor colorWithHexString:@"#333333"].CGColor;
    [noInternetView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(15);
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake([reloadDataStr widthForFont:[UIFont systemFontOfSize:16]] + 40, 40));
    }];
    return noInternetView;
}

@end
